package com.demostic.demostic_test.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.demostic.demostic_test.R;
import com.demostic.demostic_test.base.BaseActivity;
import com.demostic.demostic_test.utils.Constants;
import com.demostic.demostic_test.utils.DeviceUtils;
import com.demostic.demostic_test.utils.ToastUtils;
import com.demostic.demostic_test.utils.UserUtils;

public class FourthApActivity extends BaseActivity implements View.OnClickListener {
    final String TAG = FourthApActivity.class.getSimpleName();
    private Button btn_name_done;
    private Context context;
    private long deviceId;
    private EditText edt_name;
    private ImageView imageView;
    private String physicalId;
    private String subdomain;

    @Override // com.demostic.demostic_test.base.BaseActivity, android.support.v7.app.AppCompatActivity, android.support.v4.app.FragmentActivity, android.app.Activity
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ap_fourth);
        initView();
        getData();
    }

    private void initView() {
        this.context = this;
        this.edt_name = (EditText) findViewById(R.id.edt_name);
        this.btn_name_done = (Button) findViewById(R.id.btn_name_done);
        this.imageView = (ImageView) findViewById(R.id.image_apfourth);
        this.btn_name_done.setOnClickListener(this);
    }

    private void getData() {
        Bundle bundle;
        Intent intent = getIntent();
        if (!(intent == null || (bundle = intent.getExtras()) == null)) {
            this.physicalId = bundle.getString("physicalId");
            this.subdomain = bundle.getString("subdomain");
            this.deviceId = bundle.getLong("deviceId");
        }
        if (this.subdomain.equals(Constants.subdomain_x420)) {
            Glide.with(this.context).load(Integer.valueOf((int) R.drawable.ap_suc_420)).into(this.imageView);
        } else if (this.subdomain.equals("zhiyitest")) {
            Glide.with(this.context).load(Integer.valueOf((int) R.drawable.ap_suc_430)).into(this.imageView);
        } else if (this.subdomain.equals(Constants.subdomain_x610)) {
            Glide.with(this.context).load(Integer.valueOf((int) R.drawable.ap_suc_610)).into(this.imageView);
        } else if (this.subdomain.equals(Constants.subdomain_x620)) {
            Glide.with(this.context).load(Integer.valueOf((int) R.drawable.ap_suc_620)).into(this.imageView);
        } else if (this.subdomain.equals("ilifex660") || this.subdomain.equals("ilifex660")) {
            Glide.with(this.context).load(Integer.valueOf((int) R.drawable.ap_suc_660)).into(this.imageView);
        } else if (this.subdomain.equals(Constants.subdomain_x782)) {
            Glide.with(this.context).load(Integer.valueOf((int) R.drawable.ap_suc_782)).into(this.imageView);
        } else if (this.subdomain.equals(Constants.subdomain_x785)) {
            Glide.with(this.context).load(Integer.valueOf((int) R.drawable.ap_suc_785)).into(this.imageView);
        } else if (this.subdomain.equals(Constants.subdomain_x786) || this.subdomain.equals(Constants.subdomain_x787) || this.subdomain.equals(Constants.subdomain_x790)) {
            Glide.with(this.context).load(Integer.valueOf((int) R.drawable.ap_suc_700)).into(this.imageView);
        } else if (this.subdomain.equals(Constants.subdomain_x800)) {
            Glide.with(this.context).load(Integer.valueOf((int) R.drawable.ap_suc_800)).into(this.imageView);
        } else if (this.subdomain.equals("ilifex900") || this.subdomain.equals(Constants.subdomain_x901) || this.subdomain.equals("ilifex900")) {
            Glide.with(this.context).load(Integer.valueOf((int) R.drawable.ap_suc_900)).into(this.imageView);
        }
        if (TextUtils.isEmpty(this.edt_name.getText().toString().trim())) {
            String str = UserUtils.exChange(this.physicalId);
            this.edt_name.setText(str);
            this.edt_name.setSelection(str.length());
        }
        UserUtils.setInputFilter(this.edt_name);
    }

    @Override // android.view.View.OnClickListener
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_name_done /* 2131755208 */:
                String devName = this.edt_name.getText().toString().trim();
                if (TextUtils.isEmpty(devName)) {
                    ToastUtils.showToast(this.context, getString(R.string.setting_aty_devName_null));
                    return;
                } else if (!UserUtils.isNameMatch(devName)) {
                    ToastUtils.showToast(this.context, getString(R.string.personal_fragment_name_wrong));
                    return;
                } else {
                    DeviceUtils.renameDevice(context, deviceId, devName, null, subdomain);
//                    DeviceUtils.renameDevice(this.context, this.deviceId, devName, null, this.subdomain);
                    startActivity(new Intent(this, MainActivity.class));
                    return;
                }
            default:
                return;
        }
    }
}
